{include file="common/header"}
<body class="pear-container">
<div class="layui-row layui-col-space10">
    <div class="layui-col-md12">
        <div class="layui-card">
            <div class="layui-card-body">
                <table id="dict-table" lay-filter="dict-table"></table>
            </div>
        </div>
    </div>
</div>

</body>
<script type="text/html" id="dict-brand-toolbar">
    <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
        <i class="layui-icon layui-icon-add-1"></i>
        新增
    </button>
</script>

<script type="text/html" id="dict-province-bar">
    <button class="pear-btn pear-btn-primary pear-btn-xs" lay-event="edit">
        <i class="layui-icon">编辑</i>
    </button>
    <button class="pear-btn pear-btn-danger pear-btn-xs" lay-event="remove">
        <i class="layui-icon">删除</i>
    </button>
</script>

<script type="text/html" id="status">
    <input type="checkbox" name="task_status" value="{{d.train_id}}" lay-skin="switch" lay-text="启用|禁用"
           lay-filter="changeStatus"
           {{# if(d.task_status==1){ }} checked {{# } }}>
</script>
{include file="common/footer"}
<script>
    layui.use(['table', 'form', 'jquery', 'common', 'dropdown'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let common = layui.common;

        let MODULE_PATH = "{$Request.root}/Train/";

        table.render({
            elem: '#dict-table',
            url: MODULE_PATH + 'trainList/id/{$id}',
            cols: [
                [
                    {title: 'ID', field: 'child_id', align: 'center', width: 60},
                    {title: '训练名称', field: 'video_title', align: 'center'},
                    // {title: '训练次数', field: 'train_times', align: 'center'},
                    {title: '训练排序', field: 'train_sort', align: 'center'},
                    // {
                    //     title: '是否训练', field: 'train_status', align: 'center', templet: function (d) {
                    //         if (d.train_status) return '已训练';
                    //         else return '未训练';
                    //     }
                    // },
                    {title: '操作', toolbar: '#dict-province-bar', fixed: 'right', align: 'center', width: 135}
                ]
            ],
            cellMinWidth: 100,
            skin: 'grid',
            even: 'true',
            size: 'lg',
            page: true,
            toolbar: '#dict-brand-toolbar',
            defaultToolbar: [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter']
        });

        form.on('submit(query)', function (data) {
            table.reload('dict-table', {
                where: data.field,
                page: {curr: 1}
            })
            return false;
        });

        table.on('tool(dict-table)', function (obj) {
            if (obj.event === 'edit') {
                window.edit(obj.data['child_id']);
            } else if (obj.event === 'train') {
                window.train(obj);
            }
        });
        table.on('toolbar(dict-table)', function (obj) {
            if (obj.event === 'add') {
                window.add();
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'batchRemove') {
                window.batchRemove(obj);
            }
        });

        window.add = function () {
            layer.open({
                type: 2,
                title: '添加训练任务',
                offset: 'r',
                anim: 'slideLeft', // 从右往左
                shade: 0.1,
                shadeClose: true,
                area: common.screenBigSide(),
                content: MODULE_PATH + 'addTrain/id/{$id}'
            });
        }

        window.edit = function (id) {
            layer.open({
                type: 2,
                title: '编辑训练任务',
                offset: 'r',
                anim: 'slideLeft', // 从右往左
                shade: 0.1,
                shadeClose: true,
                area: common.screenBigSide(),
                content: MODULE_PATH + 'editTrain/id/{$id}/cid/' + id
            });
        }

        window.refresh = function () {
            table.reload('dict-table');
        }
    })
</script>
</html>
